package se.webbzon.boltzmann.player;

import java.awt.image.ImageObserver;

import se.webbzon.boltzmann.input.Input;
import se.webbzon.oschi01.worldcamera.WorldCamera;
import se.webbzon.oschi01.worldcamera.WorldCameraPane;
import se.webbzon.oschi01.worldcamera.WorldView;

public class Player extends PlayerModel {
	
	// The input of this player
	private final Input input;
	
	// The view of this player
	private final WorldView view;
	
	/*============================================================
	Constructors
	============================================================*/
	
	/** Creates a new player associated with the given input, view
	 * and default properties derived from the given player. **/
	public Player(PlayerConfiguration config, PlayerModel player) {
		this(config);
		copyFrom(player);
	}
	
	/** Creates a new player associated with the given input and view. **/
	public Player(PlayerConfiguration config) {
		this.input = config.getInput();
		this.view = config.getView();
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	/** Returns the input for this player. **/
	public Input getInput() {
		return input;
	}
	
	/** Returns the view of this player. **/
	public WorldView getView() {
		return view;
	}
	
	/** Returns true if the provided camera belongs to this player. **/
	public boolean isMyCamera(WorldCamera camera) {
		if (view == null)
			return false;
		else
			return view.getCamera() == camera;
	}
	
	/** Returns true if the provided heads-up display belongs to this player. **/
	public boolean isMyHud(WorldCameraPane hud) {
		if (view == null)
			return false;
		else
			return view.getCameraHud() == hud;
	}
	
	/** Returns true if the provided background belongs to this player. **/
	public boolean isMyBackground(WorldCameraPane background) {
		if (view == null)
			return false;
		else
			return view.getCameraBackground() == background;
	}
	
	/** Returns the image observer of this player. **/
	public ImageObserver getImageObserver() {
		return view;
	}

}
